/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.rpc.server.threads  
 */
package com.apache.rpc.server.threads;

import java.util.HashMap;
import java.util.Map;

import com.apache.database.constant.Validator;

/**
 * description:  socket线程调度
 * @author Hou Dayu 创建时间：2015-1-9  
 * @Copyright(c)2014:
 */
public class ThreadScheduler {

	private static ThreadScheduler instance;
	private Map<String, SocketConfig> jobs = new HashMap<String, SocketConfig>();

	private ThreadScheduler() {

	}

	public synchronized static ThreadScheduler getInstance() {
		if (null == instance) {
			instance = new ThreadScheduler();
		}
		return (instance);
	}

	public void setJobs(String key, SocketConfig value) {
		jobs.put(key, value);
	}

	/**
	 * 
	 * description:  启动指定任务
	 * @param key   
	 * @author Hou Dayu  
	 * @update 2015-1-9
	 */
	public void Start(String key) {
		if (!Validator.isEmpty(jobs)) {
			//执行每一个任务
			if (jobs.containsKey(key)) {
				SocketConfig config = jobs.get(key);
				Thread myThreadDelegate = new Thread(config);
				Thread myThread = new Thread(myThreadDelegate);
				myThread.start();
			}
		}
	}
}
